home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C20 / Stack1.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  1018 b   |  38 lines

  1. //: C20:Stack1.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Demonstrates the STL stack
  7. #include "../require.h"
  8. #include <iostream>
  9. #include <fstream>
  10. #include <stack>
  11. #include <list>
  12. #include <vector>
  13. #include <string>
  14. using namespace std;
  15.  
  16. // Default: deque<string>:
  17. typedef stack<string> Stack1;
  18. // Use a vector<string>:
  19. typedef stack<string, vector<string> > Stack2;
  20. // Use a list<string>:
  21. typedef stack<string, list<string> > Stack3;
  22.  
  23. int main(int argc, char* argv[]) {
  24.   requireArgs(argc, 1); // File name is argument
  25.   ifstream in(argv[1]);
  26.   assure(in, argv[1]);
  27.   Stack1 textlines; // Try the different versions
  28.   // Read file and store lines in the stack:
  29.   string line;
  30.   while(getline(in, line)) 
  31.     textlines.push(line + "\n");
  32.   // Print lines from the stack and pop them:
  33.   while(!textlines.empty()) {
  34.     cout << textlines.top();
  35.     textlines.pop();
  36.   }
  37. } ///:~
  38.